// pages/kucun/kucun.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id: '',
    zid: '',
    z_name: "",
    is_mianfei: "",
    is_wzzk: "",
    hh_num: "",
    wz_num: "",
    wz_zhekou: "",
    is_jd: "",
    jd_num: "",
    num: "",
    old_price: "",
    new_price: "",
    is_hh: "",
    times: "",
    typs: "",
    notes: ""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    var zid = options.zid
    var bgc = wx.getStorageSync('color')
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
    that.setData({
      zid: zid
    })
    that.getzhuanjia_year();
  },
  getzhuanjia_year: function (e) {
    var that = this;
    app.util.request({
      'url': "entry/wxapp/zhuanjia.zhuanjia_year",
      data: {
        openid: wx.getStorageSync('openid'),
        zid: that.data.zid
      },
      success: function (res) {

        that.setData({
          info: res.data,
          is_mianfei: res.data.is_mianfei,
          is_wzzk: res.data.is_wzzk,
          is_jd: res.data.is_jd,
          is_hh: res.data.is_hh,
          typs: res.data.typs
        })

      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  submit: function (e) {
    var that = this
    var id = that.data.info.id

    var values = e.detail.value;
    values.id = id;
    values.zid = that.data.zid;
    values.times = values.times;
    values.is_mianfei = that.data.is_mianfei;
    values.is_wzzk = that.data.is_wzzk;
    values.hh_num = values.hh_num;
    values.wz_num = values.wz_num;
    values.wz_zhekou = values.wz_zhekou;
    values.is_jd = that.data.is_jd;
    values.jd_num = values.jd_num;
    values.num = values.num;
    values.old_price = values.old_price;
    values.new_price = values.new_price;
    values.is_hh = that.data.is_hh;
    values.typs = that.data.typs;
    app.util.request({
      'url': 'entry/wxapp/zhuanjia.edit_year',
      data: values,
      success(res) {
        wx.showToast({
          title: '编辑成功',
          icon: 'none',
          duration: 1500,
          success: function (res) {
            setTimeout(function () {
              wx.navigateBack({
                detail: 1
              })
            }, 1500)
          }
        })

      }
    })
  },

  // 是否开启
  kt(e) {
    var that = this
    var values = e.detail.value
    if (values) {
      var typs = 1
    } else {
      var typs = 0
    }
    that.setData({
      typs: typs
    })
  },
  // 是否开启免费问诊
  mianfei(e) {
    var that = this
    var values = e.detail.value
    if (values) {
      var is_mianfei = 1
    } else {
      var is_mianfei = 0
    }
    that.setData({
      is_mianfei: is_mianfei
    })
  },
  // 是否开启问诊折扣
  wzzk(e) {
    var that = this
    var values = e.detail.value
    if (values) {
      var is_wzzk = 1
    } else {
      var is_wzzk = 0
    }
    that.setData({
      is_wzzk: is_wzzk
    })
  },
  // 是否开启免费会话
  is_hh(e) {
    var that = this
    var values = e.detail.value
    if (values) {
      var is_hh = 1
    } else {
      var is_hh = 0
    }
    that.setData({
      is_hh: is_hh
    })
  },
  // 是否开启免费解读
  is_jd(e) {
    var that = this
    var values = e.detail.value
    if (values) {
      var is_jd = 1
    } else {
      var is_jd = 0
    }
    that.setData({
      is_jd: is_jd
    })
  },
})